package liujia.bt.display.base
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.utils.getTimer;
	
	import liujia.bt.display.interf.IBtMouse;
	import liujia.bt.display.interf.IBtMovieClip;
	
	public class BtContainer extends Sprite
	{
		/**
		 *鼠标在舞台上的坐标 
		 */		
		public var mousePoint:Point = new Point();
		
		/**
		 *鼠标在最近一帧内X轴滑动的像素 
		 */		
		public var mouseMoveX:Number = 0;
		
		/**
		 *鼠标在最近一帧内Y轴滑动的像素 
		 */		
		public var mouseMoveY:Number = 0;
		
		/**
		 *上一帧的鼠标在舞台上的坐标，用于计算鼠标的滑动像素 
		 */		
		private var oldMousePoint:Point = new Point();
		
		/**
		 *正在播放的位图动画的播放列表
		 */		
		private var btMcVec:Vector.<IBtMovieClip> = new Vector.<IBtMovieClip>;
		
		
		public function BtContainer()
		{
			init();
		}
		
		/**
		 *初始化 
		 * @param $stage 舞台
		 * 
		 */		
		public function init():void {
			addEventListener(Event.ENTER_FRAME, onFrame);
			addMouseEvents();
		}
		
		/**
		 *Event.ENTER_FRAME触发的方法 
		 * @param e
		 * 
		 */		
		private function onFrame(e:Event):void {
			oldMousePoint.x = mousePoint.x;
			oldMousePoint.y = mousePoint.y;
			mousePoint.x = stage.mouseX;
			mousePoint.y = stage.mouseY;
			mouseMoveX = mousePoint.x - oldMousePoint.x;
			mouseMoveY = mousePoint.y - oldMousePoint.y;
		}
		
		/**
		 *舞台上的鼠标事件 
		 * @param e
		 * 
		 */		
		private function onMouse(e:MouseEvent):void {
			removeMouseEvents();
			addMouseEvents();
		}
		
		/**
		 *添加舞台鼠标事件 
		 * 
		 */		
		private function addMouseEvents():void {
			stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouse);
			stage.addEventListener(MouseEvent.MOUSE_UP, onMouse);
			stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouse);
			stage.addEventListener(MouseEvent.MOUSE_WHEEL, onMouse);
			stage.addEventListener(MouseEvent.CLICK, onMouse);
			stage.addEventListener(MouseEvent.DOUBLE_CLICK, onMouse);
		}
		
		/**
		 *移除舞台鼠标事件 
		 * 
		 */		
		private function removeMouseEvents():void {
			stage.removeEventListener(MouseEvent.MOUSE_DOWN, onMouse);
			stage.removeEventListener(MouseEvent.MOUSE_UP, onMouse);
			stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouse);
			stage.removeEventListener(MouseEvent.MOUSE_WHEEL, onMouse);
			stage.removeEventListener(MouseEvent.CLICK, onMouse);
			stage.removeEventListener(MouseEvent.DOUBLE_CLICK, onMouse);
		}
	}
}